  <template>
  <div>  
    <!--输入内容-->
       <!--此处查询没有全部查询
       修改人：刘傲杰-->
	  <el-form :inline="true" :model="filters">
				  <!--<el-select v-model="vulename" placeholder="请选择" style="margin-left:100px">
                      <el-option label="全部专业" value="" ></el-option>
					  <el-option v-for="item in options" :key="item.majorId" :label="item.majorName" :value="item.majorId"></el-option>
				  </el-select>-->
		  <el-form-item><el-input v-model="filters.majorName" placeholder="请输入专业"></el-input></el-form-item>
    <!--搜索按钮-->
   <el-button type="primary" icon="search"  @click="search()">搜索</el-button>
    <!--添加按钮-->
    <el-button type="primary" icon="edit" style="margin-left:300px" @click="addtable()">添加计划</el-button>
	  </el-form>
      <!--分页页面-->
    <el-table :data="tableData4" @selection-change="selsChange" style="width: 100% ;  margin-top:50px;"><el-table-column prop="strEnrollCreateDate" label="时间"></el-table-column>

      <el-table-column prop="majorName" label="专业"></el-table-column>

      <el-table-column prop="enrollStudentNum" label="招生人数"></el-table-column>

      <el-table-column prop="enrollTuition" label="学费信息"></el-table-column>

      <el-table-column prop="enrollEduSystem" label="学制"></el-table-column>

        <el-table-column prop="enrollArea" label="招生区域"></el-table-column>

        <el-table-column prop="enrollModel" label="招生分类"></el-table-column>

      <el-table-column fixed="right" label="操作" width="150">
         <template scope="scope">
             <el-button @click.native.prevent="updateRow(scope.row)" type="success" size="small">编辑</el-button>
             <el-button @click.native.prevent="deleteRow(scope.row)" type="danger" size="small">移除</el-button>
         </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
           <!--分页组件为完成
           修改人：刘傲杰-->
    <!--<br/>
    <div style="margin-left:500px">
     <el-pagination @current-change="handleCurrentChange" layout="total, prev, pager, next" :pageSize="15" :total="total">
     </el-pagination>
    </div>-->
      <el-col :span="24" class="toolbar">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
						 :current-page="currentPage" :page-sizes="[15, 20, 25, 30]"
						 :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" style="float:right;">
          </el-pagination>
      </el-col>
    <!--编辑界面-->
		<el-dialog title="招生计划添加" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="100px" :rules="editFormRules" ref="editForm">
       <el-form-item label="专业选择">
				  <el-select v-model="editForm.majorId" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.majorId"
                :label="item.majorName"
                :value="item.majorId">
              </el-option>
           </el-select>
        	</el-form-item>   
				<el-form-item label="招生人数"  prop="enrollStudentNum">
					<el-input v-model="editForm.enrollStudentNum" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item  prop="enrollTuition" label="学费信息">
					<el-input v-model="editForm.enrollTuition" auto-complete="off"></el-input>
				</el-form-item>
				<!--学制改为下拉框 value：1 2 3 4
				修改人：刘傲杰 2017/8/8-->
				<!--<el-form-item prop="enrollEduSystem" label="学制">
					<el-input v-model="editForm.enrollEduSystem" auto-complete="off"></el-input>
				</el-form-item>-->

				<el-form-item label="学制" prop="enrollEduSystem">
					<el-select v-model="editForm.enrollEduSystem" auto-complete="off">
						<el-option label="1" value="1" ></el-option>
						<el-option label="2" value="2" ></el-option>
						<el-option label="3" value="3" ></el-option>
						<el-option label="4" value="4" ></el-option>
					</el-select>
				</el-form-item>

				<el-form-item prop="enrollArea" label="招生区域">
					<el-input v-model="editForm.enrollArea" type="text" auto-complete="off"></el-input>
				</el-form-item>
        <el-form-item prop="enrollModel" label="招生形式">
					<el-input v-model="editForm.enrollModel" type="text" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">保存</el-button>

			</div>
		</el-dialog>







    <!--修改-->
		<el-dialog title="招生计划修改" v-model="updateFormVisible" :close-on-click-modal="false">
			<el-form :model="updateForm" label-width="100px" :rules="updateFormRules" ref="updateForm">
       <el-form-item label="专业选择">
				  <el-select v-model="updateForm.majorId" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.majorId"
                :label="item.majorName"
                :value="item.majorId">
              </el-option>
           </el-select>
        	</el-form-item>   
				<el-form-item label="招生人数"  prop="enrollStudentNum">
					<el-input v-model="updateForm.enrollStudentNum" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item  prop="enrollTuition" label="学费信息">
					<el-input v-model="updateForm.enrollTuition" auto-complete="off"></el-input>
				</el-form-item>
				<!--学制改为下拉框 value：1 2 3 4
				修改人：刘傲杰 2017/8/8-->
				<!--<el-form-item prop="enrollEduSystem" label="学制">
					<el-input v-model="updateForm.enrollEduSystem" auto-complete="off"></el-input>
				</el-form-item>-->
				<el-form-item label="学制" prop="enrollEduSystem">
					<el-select v-model="updateForm.enrollEduSystem" auto-complete="off">
						<el-option label="1" value="1" ></el-option>
						<el-option label="2" value="2" ></el-option>
						<el-option label="3" value="3" ></el-option>
						<el-option label="4" value="4" ></el-option>
					</el-select>
				</el-form-item>
				<el-form-item prop="enrollArea" label="招生区域">
					<el-input v-model="updateForm.enrollArea" type="text" auto-complete="off"></el-input>
				</el-form-item>
        <el-form-item prop="enrollModel" label="招生形式">
					<el-input v-model="updateForm.enrollModel" type="text" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="updateFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="updateSubmit" :loading="updateLoading">保存</el-button>

			</div>
		</el-dialog>


  </div>  
  </template>

<script>
  import { enrollpage } from '../../api/api'
	 import  { addenroll } from '../../api/api'
   import { getEnroll } from '../../api/api'
   import { updateEnroll } from '../../api/api'
   import { deleteEnroll} from '../../api/api'


  export default {
      //页面数据
      data() {

          return {
              filters:{
                  majorId:'',
                  majorName:''
              },
              total:0,//列表总条数
              pageSize:15,//每页条数
              currentPage:1,//当前页码
              listLoading:false,
              sels:[],//lie
              vulename:"",

              options:[
              ],
              tableData4:[],
              input:'',


              editFormVisible: false,//编辑界面是否显示
              editLoading: false,
              editFormRules: {

                  enrollModel: [
                      { required: true, message: '不能为空', trigger: 'blur' }
                  ],
                  enrollStudentNum: [
                      { required: true,  message: '不能为空', trigger: 'blur' }
                  ],
                  enrollTuition: [
                      { required: true, message: '不能为空', trigger: 'blur' }
                  ],
                  enrollArea: [
                      { required: true, message: '不能为空', trigger: 'blur' }
                  ]
              },
              //增加界面界面
              editForm: {
                  majorId: '',
                  //招生人数
                  enrollStudentNum: '',
                  //学费
                  enrollTuition: '',
                  //学制
                  enrollEduSystem:'',
                  //招生区域
                  enrollArea: '',
                  //招生形式
                  enrollModel:'',
              },






              updateFormVisible: false,//修改界面是否显示
              updateLoading: false,
              updateFormRules: {
                  // 		enrollModel: [
                  // 	{ required: true, message: '不能为空', trigger: 'blur' }
                  // ],
                  // enrollStudentNum: [
                  // 	{ required: true,  message: '不能为空', trigger: 'blur' }
                  // ],
                  // enrollTuition: [
                  // 	{ required: true, message: '不能为空', trigger: 'blur' }
                  // ],
                  // enrollArea: [
                  // 	{ required: true, message: '不能为空', trigger: 'blur' }
                  // ]
              },
              //修改界面数据
              updateForm: {
                  majorId: '',
                  //招生人数
                  enrollStudentNum: '',
                  //学费
                  enrollTuition: '',
                  //学制
                  enrollEduSystem: '',
                  //招生区域
                  enrollArea: '',
                  //招生形式
                  enrollModel:'',
              },

              /*total:0,//列表总条数
              pageSize:15,//每页条数
              currentPage:1,//当前页码
              listLoading:false,
              sels:[],//lie
              vulename:"",*/
          }

      },
    //方法
    methods: {

      

      //添加计划
       addtable(){
      
        this.editFormVisible=true;
      },
     editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
						this.editLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.editForm);
							addenroll(para).then((res) => {
								 this.editLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
							this.$refs.editForm.resetFields();
              this.editForm.majorId='';
								this.editFormVisible = false;
								this.listAll();
							});
						});
					}
				});
			},

     // 删除触发方法
      deleteRow(row) {
       	this.$confirm('确认提交吗？', '提示', {}).then(() => {
          let para ={enroll_id:row.enroll_id};
          deleteEnroll(para)
          	this.listAll();
          
         });
      },
      //修改触发方法
      updateRow(row){
        // alert(row.enroll_id);
          this.updateFormVisible=true;
         let para={enroll_id:row.enroll_id};
        
          getEnroll(para).then((res) => {
         	 this.updateForm=res.resData;
          });
      },
      //修改确认
      updateSubmit:function(){
        	this.$refs.updateForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
						this.updateLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.updateForm);

							updateEnroll(para).then((res) => {
								 this.updateLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								 	this.$refs.updateForm.resetFields();
                  this.updateForm.majorId='';
								  this.updateFormVisible= false ;
								this.listAll();
							});
						});
					}
				});
      },
       /*handleCurrentChange(val){
        	this.currentPage = val;
          // alert(val)
          this.listAll();
        },*/

        
      search(){
           let para = {
               pageSize: this.pageSize,
               currentPage: this.currentPage,
			   majorId:this.filters.majorId,
			   majorname:this.filters.majorName,
           }
          this.listLoading = true;
          enrollpage(para).then((res) => {
              this.total=res.resData.listEnro.total;

              this.tableData4=res.resData.listEnro.list;

              this.listLoading = false;
          });
      },
        // 列选择
        selsChange: function (sels) {
            this.sels = sels;
        },

      //分页默认数据
       listAll(){
          let para={pageSize:this.pageSize,
              currentPage:this.currentPage};
          enrollpage(para).then((res) => { 
            this.tableData4=res.resData.listEnro.list;
            this.options=res.resData.listMajor;
             this.total=res.resData.listEnro.total;
           //	 this.tableData4=res.data;
          //  this.total=res.data;

				});
      },
            // 分页组件
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                this.search();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage = val;
                this.search();
            },
    },


    //初始化内容
    mounted(){ 
      this.listAll();
    }

  };
</script>


